import * as constants from './constants'
// 引入immutable 使state变为不可变对象
import { fromJS } from 'immutable'

const defaultState = fromJS({
  focus: false,
  list: [],
  mouseIn: false,
  pageNum: 1,
  totalPage: 1
})
// state 变为 redux-immutable 对象了 该对象中的方法 提供 get getIn 来获取 set 来赋值
export default (state = defaultState, action) => {
  switch (action.type) {
    case constants.SEARCH_FOCUS:
      return state.set('focus', true)
    case constants.SEARCH_BLUR:
      return state.set('focus', false)
    case constants.GET_SEARCH_LIST:
      return state.set('list', action.list).set('totalPage', action.totalPage)
    // return
    case constants.ON_MOUSE_ENTER:
      return state.set('mouseIn', true)
    case constants.ON_MOUSE_LEAVE:
      return state.set('mouseIn', false)
    case constants.Change_Page_Num:
      // console.log(action.pageNum)
      return state.set('pageNum', action.pageNum)
    default:
      return state
  }

  // if (action.type === constants.SEARCH_FOCUS) {
  //   // 引入immutable 修改属性
  //   return state.set('focus', true)
  //   // {
  //   //   focus: true
  //   // }
  // }
  // if (action.type === constants.SEARCH_BLUR) {
  //   return state.set('focus', false)
  // }
  // return state
}